package com.dcl.spride;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class NamePass {
	String name;
	String pass;

	NamePass() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public void readFromFile() {
		File file = new File("./login.properties");
		FileInputStream inputstream =null;
		try {
			 inputstream = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		Properties pro = new Properties();
		try {
			pro.load(inputstream);
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.name=pro.getProperty("uname");
		this.pass=pro.getProperty("upass");
	}

	public void reNameAndPass(String name, String pass) {
		File file = new File("./login.properties");
		FileOutputStream outputstream =null;
		try {
			 outputstream = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		Properties pro = new Properties();
		pro.setProperty("uname", name);
		pro.setProperty("upass", pass);
		this.name=name;
		this.pass=pass;
		try {
			pro.store(outputstream, null);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

	public static void main(String[] args) {
		NamePass name = new NamePass();
		name.reNameAndPass("admin", "admin");
		name.readFromFile();
		System.out.println(name.getName());
		System.out.println(name.getPass());
	}

}
